package com.lufei4.chestnut.net2;

import android.app.ProgressDialog;
import android.util.Log;

import com.blankj.utilcode.util.ToastUtils;

import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public abstract class BaseObserver<T> implements Observer<BaseResponse<T>> {
    private static final String TAG = "BaseObserver";
    @Override
    public void onSubscribe(Disposable d) {
        Log.e(TAG, "onSubscribe: " );

    }

    @Override
    public void onNext(BaseResponse<T> response) {
        //在这边对 基础数据 进行统一处理  举个例子：
        if(response.getErrorCode()==0){
            ToastUtils.showShort("请求成功");
            onSuccess(response.getData());
        }else{
            onFailure(null,response.getErrorMsg());
        }
    }

    @Override
    public void onError(Throwable e) {
        Log.e(TAG, "Throwable: " + e.getMessage());

    }

    @Override
    public void onComplete() {
        Log.e(TAG, "onComplete: " );

    }
    public abstract void onSuccess(T demo);

    public abstract void onFailure(Throwable e,String errorMsg);
}
